﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.AccountingObjectCategory
{
    public class AccountingObjectCategoryPresenter : Presenter<IAccountingObjectCategoryView>
    {
        public AccountingObjectCategoryPresenter(IAccountingObjectCategoryView view)
            : base(view)
        {
        }

        public void Display(string accountingObjectCategoryId)
        {
            if (accountingObjectCategoryId == null) return;

            var accountingObjectCategory = Model.GetAccountingObjectCategory(accountingObjectCategoryId);

            View.AccountingObjectCategoryID = accountingObjectCategory.AccountingObjectCategoryID;
            View.AccountingObjectCategoryCode = accountingObjectCategory.AccountingObjectCategoryCode;
            View.AccountingObjectCategoryName = accountingObjectCategory.AccountingObjectCategoryName;
            View.ParentID = accountingObjectCategory.ParentID;
            View.IsParent = accountingObjectCategory.IsParent;
            View.IsCustomer = accountingObjectCategory.IsCustomer;
            View.IsVendor = accountingObjectCategory.IsVendor;
            View.IsEmployee = accountingObjectCategory.IsEmployee;
            View.RestaurantID = accountingObjectCategory.RestaurantID;
            View.Description = accountingObjectCategory.Description;
            View.IsActive = accountingObjectCategory.IsActive;
        }

        public int Save()
        {
            var accountingObjectCategory = new AccountingObjectCategoryModel
            {
                AccountingObjectCategoryID = View.AccountingObjectCategoryID,
                AccountingObjectCategoryCode = View.AccountingObjectCategoryCode,
                AccountingObjectCategoryName = View.AccountingObjectCategoryName,
                ParentID = View.ParentID,
                IsParent = View.IsParent,
                IsCustomer = View.IsCustomer,
                IsVendor = View.IsVendor,
                IsEmployee = View.IsEmployee,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (accountingObjectCategory.AccountingObjectCategoryID == null)
                return Model.AddAccountingObjectCategory(accountingObjectCategory);
            else
                return Model.UpdateAccountingObjectCategory(accountingObjectCategory);
        }

        public int Delete(string accountingObjectCategoryId)
        {
            return Model.DeleteAccountingObjectCategory(accountingObjectCategoryId);
        }
    }
}
